rm(list = ls())

library(readxl)
library(zoo)
library(dplyr)
library(magrittr)
library(ggplot2)


d <- read_excel(here('ito_price_series.xlsx'))


d$month_year <- paste0(d$yil,'-', d$ay)

d$month_yearDate <- as.yearmon(d$month_year)

d$month_yearDate <- as.Date(d$month_yearDate)

d_long <- d %>% select(month_yearDate, ito_change, tufe_change) %>% tidyr::pivot_longer(ito_change:tufe_change)


d_long$price_series <- ifelse(d_long$name == 'ito_change', 'Cost of Living Index \n (Istanbul Chamber of Commerce)', 'Consumer Price Index \n (Turkish Statistical Institute)')

d_long <- d_long %>% filter(month_yearDate > '2018-12-31' & month_yearDate < '2024-01-01')

price_plot <- ggplot(d_long, aes(x = month_yearDate, y = value, color = price_series)) + geom_point() + geom_smooth(span = 0.2, se = FALSE) + theme_bw() + theme(legend.position = 'bottom', axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) + labs(x = '', y = 'Monthly inflation (% change)', color = 'Price series') + scale_x_date(date_breaks = "2 months", date_labels = "%Y-%m") + geom_vline(xintercept =c(as.Date('2021-09-24'), as.Date('2021-10-22'), as.Date('2021-09-24'), as.Date('2021-10-22'), as.Date('2021-11-19'), as.Date('2021-12-17'), as.Date('2022-08-19'), as.Date('2022-09-23'), as.Date('2022-10-21'), as.Date('2022-11-25'), as.Date('2023-02-23'))) + scale_y_continuous(breaks = round(seq(min(d_long$value), max(d_long$value), by = 1),1))


ggsave(price_plot, file = here('figure_1.pdf'), width = 7, height = 6)
